//get
async function ajaxGet(url, param) {
    let info = null;
    await axios.get(url, {params: param}).then(e => {
        info = e.data;
    })
    return info;
}

//post
async function ajaxPost(url, param) {
    let info = null;
    let obj = new URLSearchParams();
    for (field in param) {
        obj.append(field, param[field]);
    }
    await axios.post(url, obj).then(e => {
        info = e.data;
    })
    return info;
}

function $(id) {
    return document.getElementById(id);
}

//获取类名下数组元素是否被选中
function $N(name) {
    let obj = document.getElementsByName(name);
    if (obj != null) {
        for (let i = 0; i < obj.length; i++) {
            if (obj[i].checked) {
                return obj[i];
            }
        }
    }
    return null;
}

//退出账号同时摧毁当前session
async function outAccount() {
    let result = await ajaxGet("/user/outAccount");
    if (result == "ok") {
        location.href = "/html/login/login.html";
    } else {
        alert("服务器出错了");
    }
}